package com.grep.web.tool;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.grep.extra.factory.utils.RegexUtil;
import com.grep.extra.factory.utils.JsoupUtil;
public class GrepTest {
	public static Map<String,String> getRegexContent(String url,List<Target> targets){
		Map<String,String> retMap = new HashMap<String,String>();
		JsoupUtil jsoup = null;
		try{
			jsoup = new JsoupUtil(url);
		}catch(Exception e){
			retMap.put("error","url 连接错误");
			return null;
		}
		
		
		String content = jsoup.getHtmlText();
		for(Target target:targets){
			String beginRegex = target.getBeginRegex();
			String endRegex = target.getEndRegex();
			if(beginRegex==null || beginRegex.equals("") || endRegex==null || endRegex.equals("")){
				retMap.put(target.getTargetName(), "error:指标不能为空");
			}else{
				String regok = RegexUtil.getValueByRegex(target.getBeginRegex(), target.getEndRegex(), content);
				retMap.put(target.getTargetName(),regok);
//				System.out.println(target.getTargetName()+":"+regok);
			}
		}
		return retMap;
	}
}
